package com.leoren.blog.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.leoren.blog.entity.Follow;
import com.leoren.blog.dao.FollowMapper;
import com.leoren.blog.service.FollowService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Leoren
 * @since 2023年11月24日
 */
@Service
public class FollowServiceImpl extends ServiceImpl<FollowMapper, Follow> implements FollowService {

    @Autowired
    private FollowMapper followMapper;

    @Override
    public int follow(int followerId, int followeeId) {
        Follow follow  = followMapper.hasFollow(followerId, followeeId);
        if(follow != null){
            return -1;
        }
        Follow followNew = new Follow(followerId, followeeId);
        return followMapper.insert(followNew);
    }

    @Override
    public int unFollow(int followerId, int followeeId) {
        Follow follow = followMapper.hasFollow(followerId, followeeId);
        if(follow == null){
            return -1;
        }
        return followMapper.deleteById(follow);
    }
}
